package com.catclay.adultmoon.controller.order;

import com.catclay.adultmoon.pojo.Order;
import com.catclay.adultmoon.service.logistics.LogisticsService;
import com.catclay.adultmoon.service.order.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    LogisticsService logisticsService;

    @Autowired
    OrderService orderService;

    @GetMapping("/logisticsInfo")
    public String getLogisticsInfo(Model model,@RequestParam String recePhone){
        String lsi = logisticsService.getlogisticsNo(recePhone);
        model.addAttribute("logisticsNo",lsi);
        return lsi;
    }

    @GetMapping("/all")
    @ResponseBody
    public List<Order> getOrderList(){
        List<Order> orderList = orderService.getOrderList();
        return orderList;
    }

    @PostMapping("/add")
    @ResponseBody
    public String add(@RequestBody Order order){
        int result = orderService.add(order);
        return result==1?"success":"fail";
    }

    @GetMapping("/del")
    @ResponseBody
    public String del(@RequestParam Integer id){
        int result = orderService.del(id);
        return result==1?"success":"fail";
    }
}
